﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;

namespace G.Controls
{

        [TemplateVisualState(Name = "Pressed", GroupName = "CommonStates")]
        [TemplateVisualState(Name = "Normal", GroupName = "CommonStates")]
        public class ImageButton : ButtonBase
        {
            public static readonly DependencyProperty ImageStrecthProperty = DependencyProperty.Register("ImageStrecth", typeof(Stretch), typeof(ImageButton), null);
            public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(ImageButton), null);

            public Stretch ImageStrecth
            {
                get { return (Stretch)this.GetValue(ImageButton.ImageStrecthProperty); }
                set { this.SetValue(ImageButton.ImageStrecthProperty, value); }
            }
            public ImageSource ImageSource
            {
                get
                {
                    return (ImageSource)this.GetValue(ImageSourceProperty);
                }
                set
                {
                    this.SetValue(ImageSourceProperty, value);
                }
            }
            public ImageButton()
                : base()
            {
                this.DefaultStyleKey = typeof(ImageButton);
            }
            public override void OnApplyTemplate()
            {
                base.OnApplyTemplate();
            }

            protected override void OnIsPressedChanged(DependencyPropertyChangedEventArgs e)
            {
                base.OnIsPressedChanged(e);
                if (this.IsPressed)
                {
                    VisualStateManager.GoToState(this, "Pressed", false);
                }
                else
                {
                    VisualStateManager.GoToState(this, "Normal", false);
                }
            }

        }

}
